package cc.geguo.cookiedemo;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者  Administrator
 * 时间  2017/2/16 20:11
 * 文件  SessionDemo
 * 描述
 */
public class CookiePractice extends HttpServlet {


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String currentTime = simpleDateFormat.format(new Date());
		String lastTime="";
		Cookie[] old = request.getCookies();
		if (old!=null){
			lastTime = old[0].getValue();
		}

		request.getSession().getAttribute("demo1");
		Cookie cookie = new Cookie("lastTime",currentTime);
		response.getWriter().write("lastTime"+lastTime);
		response.addCookie(cookie);
	}
}
